<?php

// 会员表

namespace app\client\model;

use think\Model;
use think\Session;
use think\Request;
use app\console\model\MemberInfo as MemberInfoModel;

class Member extends Model
{

    // 会员表 会员附属表 关联
    public function MemberInfo()
    {
        return $this->hasOne('MemberInfo','member_id','id');
    }


    // 登录方法
    public static function login()
    {
        $map = [
            'username'    => Request::instance()->post('username', '', 'strtolower'),
            'password'    => Request::instance()->post('password', '', 'mcs'),
            'status'      => 1,
            'shop_status' => 1
        ];

        $find = self::where($map)->find();

        $info = (new MemberInfo)->where('member_id',$find['id'])->find();

        // 用户名&密码 验证成功
        if ($find) {
            Session::set('shop_id', $find['id']);
            Session::set('shop_user', $find['username']);

            Session::set('shop_name', $info['name']);
            Session::set('shop_avatar', $info['avatar']);
            return true;
        }
        return false;
    }
}